package com.invengo.module_check.data.repsitory.common.source;

import android.annotation.SuppressLint;

import com.invengo.library_db.entity.module_check.offline.UserBean;
import com.invengo.module_check.data.entity.FeatureBean;

import java.util.ArrayList;

import io.reactivex.Observable;
import java8.util.Optional;
import me.goldze.mvvmhabit.http.BaseBean;
import me.goldze.mvvmhabit.utils.cache.ACache;
import me.goldze.mvvmhabit.utils.cache.AKey;

public interface CommonSource {
    Observable<BaseBean<UserBean>> checkLogin(String account, String password);
     default void saveLoginUser(String userName,String passWord,int UserId){

         Optional.ofNullable(userName).ifPresent(name-> ACache.getInstance().put(AKey.CACHE_USERNAME, name));
         Optional.ofNullable(passWord).ifPresent(pass-> ACache.getInstance().put(AKey.CACHE_PASSWORD, pass));
         Optional.ofNullable(UserId).ifPresent(staffId-> ACache.getInstance().put(AKey.CACHE_USER_STAFF_ID, staffId));
    }
    default void cleanUser(){
         ACache.getInstance().put(AKey.CACHE_USERNAME, "");
         ACache.getInstance().put(AKey.CACHE_PASSWORD, "");
         ACache.getInstance().put(AKey.CACHE_USER_STAFF_ID, "");
    }


    default ArrayList<FeatureBean> getFeatureList() {
        return (ArrayList<FeatureBean>) ACache.getInstance().getAsObject(AKey.CACHE_FEATURE_LIST);
    }

}
